<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/add.css"/>
    <link rel="stylesheet" href="../../assets/css/layui.css">
    <link rel="stylesheet" href="../../assets/css/view.css"/>
</head>
<body>
<div id="app">
    <div class="header">
        <span>添加快递员</span>
    </div>
    <form id="form">
        <div class="content">

            <table>
                <tr>
                    <td class="text-right">姓名</td>
                    <td class="content_right"><input id="name" class="input" placeholder="请输入姓名"></td>
                </tr>
                <tr>
                    <td class="text-right">手机号码</td>
                    <td class="content_right"><input id="phone" class="input" placeholder="请输入手机号码"></td>
                </tr>
                <tr>
                    <td class="text-right">身份证号码</td>
                    <td class="content_right"><input id="number" class="input" placeholder="请输入身份证号码"></td>
                </tr>
                <tr>
                    <td class="text-right">密码</td>
                    <td class="content_right"><input id="password" class="input" placeholder="请输入8-12位字母数字组成的密码"></td>
                </tr>
                <tr>
                    <td></td>
                    <td class="content_right">
                        <span id="load" class="btn btn-info">立即提交</span>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</div>
<script src="/qrcode/jquery2.1.4.js"></script>
<script src="/layer/layer.js"></script>
<script>
    function checkName(name) {
        var reg = new RegExp(/[a-zA-Z]{5,10}/i);
        if (reg.test(name))
            return true;
        layer.msg('用户名错误（5-10位字母组成）')
        return false;
    }
    function checkPhone(phone) {
        var reg = new RegExp(/^1[3|4|5|7|8][0-9]{9}$/i);
        if (reg.test(phone))
            return true;
        layer.msg('电话格式错误')
        return false;
    }
    function checkNumber(number) {
        var reg = new RegExp(/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/);
        if (reg.test(number))
            return true;
        layer.msg('身份证格式错误')
        return false;
    }
    function checkPassword(password) {
        var reg = new RegExp(/^\w\w{7,11}$/i)
        if (reg.test(password))
            return true;
        layer.msg('密码不符合8-12位字母数字组成')
        return false;
    }
    $(function () {
        $("#load").click(function () {
            var name = $("input:eq(0)").val();
            var phone = $("input:eq(1)").val();
            var number = $("input:eq(2)").val();
            var password = $("input:eq(3)").val();
            if (checkName(name) && checkPhone(phone) && checkNumber(number) && checkPassword(password)) {
                var windowId = layer.load();
                $.post("/user/insert.udo", {
                    name: name,
                    phone: phone,
                    number: number,
                    password: password,
                    identity: 0
                }, function (data) {
                    layer.close(windowId);
                    layer.msg(data.result);
                    if (data.status == 0) {
                        //录入成功,清空所有数据
                        $("input").val("");
                    } else {
                        //录入失败
                    }
                });
            }
        });
    });
</script>
</body>
</html>
